package _06_动态规划;

public class _746_使用最小花费爬楼梯 {

    public static void main(String[] args) {

        _746_使用最小花费爬楼梯 v = new _746_使用最小花费爬楼梯();

        int[] ins = {10, 15, 20};
        System.out.println(v.minCostClimbingStairs(ins));

    }

    public int minCostClimbingStairs(int[] cost) {
        int first = 0;
        int second = 0;
        for (int i = 2; i <= cost.length; i++) {
            int temp = second;
            second = Math.min(first + cost[i - 2], second + cost[i - 1]);
            first = temp;
        }
        return second;
    }

    public int minCostClimbingStairs1(int[] cost) {
        int first = cost[0];
        int second = cost[1];
        for (int i = 2; i < cost.length; i++) {
            int temp = second;
            second = Math.min(first, second) + cost[i];
            first = temp;
        }
        return Math.min(first, second);
    }

}
